<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@include file="common/head.jsp"%>
<div class="layui-body">
    <div style="padding: 15px">
        <form class="layui-form" >
            <blockquote class="layui-elem-quote">基本信息</blockquote>
            <div class="layui-form-item">
                <label class="layui-form-label">管理员ID</label>
                <div class="layui-input-inline">
                    <input type="text" name="rootID" disabled="disabled" placeholder="" class="layui-input" id="rootID">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">管理员姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="rootName" disabled="disabled" placeholder="" class="layui-input" id="rootName">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">管理员留言</label>
                <div class="layui-input-inline">
                    <input type="text" name="rootMes" maxlength="100" placeholder="管理员留言" id="rootMsg" class="layui-input">
                </div>
                <a class="layui-btn" id="button_save">保存留言</a>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">绑定微信</label>
                <div class="layui-input-block layui-word-aux">
                    <a class="layui-btn" id="weixin"><i class="layui-icon layui-icon-login-wechat" style="font-size: 24px;"></i>绑定微信</a>
                    第一时间  get  最新审批消息
                </div>
            </div>
            <blockquote class="layui-elem-quote">修改密码</blockquote>
            <div class="layui-form-item">
                <label class="layui-form-label">原密码</label>
                <div class="layui-input-inline">
                    <input autocomplete="new-password" type="password" name="password" minlength="8" maxlength="16"
                           oninput="value=value.replace(/[^\a-\z\A-\Z0-9\+\-\_\!\@\#\$\%\^\&\*\.]/g,'')" required lay-verify="required"
                           placeholder="请输入密码" autocomplete="off" class="layui-input" id="input_oldpwd">
                </div>
                <div style="color: red; font-size: larger;">*</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" minlength="8" maxlength="16"
                           oninput="value=value.replace(/[^\a-\z\A-\Z0-9\+\-\_\!\@\#\$\%\^\&\*\.]/g,'')" required lay-verify="required"
                           placeholder="请输入密码" autocomplete="off" class="layui-input"  id="input_newpwd">
                </div>
                <div style="color: red; font-size: larger;">*</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" minlength="8" maxlength="16"
                           oninput="value=value.replace(/[^\a-\z\A-\Z0-9\+\-\_\!\@\#\$\%\^\&\*\.]/g,'')" required lay-verify="required"
                           placeholder="请输入密码" autocomplete="off" class="layui-input" id="input_againpwd">
                </div>
                <div style="color: red; font-size: larger;">*</div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button id="button_modify" class="layui-btn" lay-submit lay-filter="formDemo">确认修改</button>
                </div>
            </div>
            <blockquote class="layui-elem-quote">审批历史</blockquote>
            <div style="margin-left: 3%">
                该功能暂不开放
            </div>
            </br>
            </br>
            </br>
        </form>
    </div>
</div>
<%@include file="/jsp/root/common/foot.jsp" %>
<%--引入jform库--%>
<script type="text/javascript" src="<%=path%>/js/jquery-form.js"></script>
<script type="text/javascript">
    $('#input_oldpwd').on('click', function(){
        let that = this;
        layer.tips("<span style='font-size:14px'>"+'请输入原密码'+"</span>", that,{ tips: [2, '#009688'],time:3000});
    });
    $('#input_newpwd').on('click', function(){
        let that = this;
        layer.tips("<span style='font-size:14px'>"+'请设置8-16位新密码，可包括英文大小写、数字、特殊字符!@#$%^&*_+-.'+"</span>", that,{ tips: [2, '#009688'],time:3000});
    });
    $('#input_againpwd').on('click', function(){
        let that = this;
        layer.tips("<span style='font-size:14px'>"+'请再输一遍新密码'+"</span>", that,{ tips: [2, '#009688'],time:3000});
    });
    $('#rootMsg').on('click', function(){
        let that = this;
        layer.tips("<span style='font-size:14px'>"+'您的留言将显示在登陆界面，忘记密码的用户可通过留言找到您'+"</span>", that,{ tips: [2, '#009688'],time:3000});
    });
    $('.layui-form').on('submit', function () {
        let oldpwd = $('#input_oldpwd').val();
        let newpwd = $('#input_newpwd').val();
        let againpwd = $('#input_againpwd').val();

        /*表单输入验证*/
        if (oldpwd.length < 8 || newpwd.length < 8 || againpwd.length < 8) {
            layui.use('layer',function () {
                var layer=layui.layer;
                layer.alert("输入密码位数不足8位，请重新输入！");
            })
            $('#input_oldpwd').val("");
            $('#input_newpwd').val("");
            $('#input_againpwd').val("");
        } else if (newpwd == againpwd) {
            if (newpwd=='00000000') {
                layer.alert("不能和初始密码一致，请重新设置！");
                $('#input_newpwd').val("");
                $('#input_againpwd').val("");
            }else if (newpwd == oldpwd){
                layer.alert("新密码不能和旧密码一致，请重新设置！");
                $('#input_newpwd').val("");
                $('#input_againpwd').val("");
            }else {
                $(this).ajaxSubmit({
                    type: "POST"
                    ,
                    url: '${pageContext.request.contextPath}/jsp/root.do?method=pwdModify&oldpwd=' + oldpwd + '&newpwd=' + newpwd
                    ,
                    data: 'json'
                    ,
                    success: function (data) {
                        if (data.ok == "yes") {
                            alert("密码修改成功，请重新登录！");
                            window.location.href = "${pageContext.request.contextPath}/jsp/logout.do";
                        } else {
                            layui.use('layer',function () {
                                var layer=layui.layer;
                                layer.alert("原密码错误！");
                            })
                            $('#input_oldpwd').val("");
                            $('#input_newpwd').val("");
                            $('#input_againpwd').val("");
                        }
                    }
                });
            }
        } else {
            layer.alert("确认密码与新密码不一致！");
            $('#input_newpwd').val("");
            $('#input_againpwd').val("");
        }
        return false;
    });
    $('#button_save').on('click',function () {
        if ($('#rootMsg').val()!='' && $('#rootMsg').prop('disabled')!=true){
            $.ajax({
                type: "POST"
                ,dataType:"json"
                ,url:"${pageContext.request.contextPath}/jsp/root.do?method=setRootMsg&userCode="+$('#rootID').attr('placeholder')+"&rootMsg="+$('#rootMsg').val()
                ,success:function (data) {
                    if (data.ok === "yes"){
                        layer.msg('留言设置成功',{time:2000});
                    }else if (data.ok === "no"){
                        layer.msg('留言设置失败');
                    }
                }
                ,error:function () {
                    layer.msg('由于异常原因，留言设置失败');
                }
            })
        }else if ($('#rootMsg').prop('disabled')==true){
            layer.msg('只有一级管理员可以设置留言');
        }else {
            layer.msg('留言不能设置为空');
        }
    })
</script>
<%--按钮的后台操作--%>
<script type="text/javascript">
    $('#weixin').on('click',function () {
        $.ajax({
            type:'POST'
            ,url: '${pageContext.request.contextPath}/weixin.do?method=bind'
            ,dataType:'json'
            ,success:function (data) {
                if (data!=null && data.code == 200){
                    window.open(data.url,"_blank");
                }if (data!=null && data.code == 300){
                    layer.msg('您已绑定微信。若要解绑，请前往 西安科技大学实验室资源申请平台（LMS）公众号 解除绑定！');
                }if(data!=null && data.code == 404){
                    layer.msg('服务异常，绑定失败');
                }
            }
        })
    })
</script>
</body>
</html>